# *coding:utf-8 *
import numpy as np

from flask import Flask, render_template

app = Flask(__name__)


@app.route('/hello')
def hello():
    return 'Hello Big Screen 2022'

@app.route('/')
def index():
    return render_template('index.html')

# 各月销售和利润情况
@app.route('/sales_month')
def sales_month():
    # 读取data/sales_month.csv中的各月销售数据，提供给浏览器端调用
    with open("data/sales_month.csv", encoding='utf-8') as f:
        # 读取数据
        csv_data = np.loadtxt(f, str, delimiter=",", skiprows=1) # skiprows=1 跳过csv数据的首行

        data = csv_data.T # 行转列

        data_list = data.tolist()

        data_month = data_list[0] # 月份
        data_sales = data_list[1] # 销售额
        data_profit = data_list[2] # 利润

    return {'month': data_month, 'sales': data_sales, 'profit': data_profit}


if __name__ == '__main__':
    app.run()
